package com.dianneng.show.util;

import com.blankj.utilcode.util.Utils;

public class CommandUtil {

    //使用1字节就可以表示b
    public static String numToHex8(int b) {
        return String.format("%02x", b);//2表示需要两个16进行数
    }


    public static String getChangLiang(int yuzhi,int yanshi,int liangdu){
        StringBuffer sb=new StringBuffer();

        //网关编号
        String sn=ACache.get(Utils.getApp()).getAsString(Constant.DEVICE_SN);
        if (sn.length()!=16){
            sn="18F352103A617D85";
        }
        sb.append(sn);
        //工作模式
        sb.append("f0");
        //照度阈值
        sb.append(numToHex8(yuzhi));
        //高亮延时
        sb.append(numToHex8(yanshi));
        //常亮亮度
        sb.append(numToHex8(liangdu));

        return sb.toString();
    }

    public static String getJieNeng(int yuzhi,int yanshi,boolean isYing,int jiangliang,int gaoliangchang,int jianan,int gaoliang,int jieneng){
        StringBuffer sb=new StringBuffer();

        //网关编号
        String sn=ACache.get(Utils.getApp()).getAsString(Constant.DEVICE_SN);
        if (sn.length()!=16){
            sn="18F352103A617D85";
        }
        sb.append(sn);
        //工作模式
        sb.append("0f");
        //照度阈值
        sb.append(numToHex8(yuzhi));
        //高亮延时
        sb.append(numToHex8(yanshi));
        //控制模式
        if (isYing){
            sb.append("a5");
        }else {
            sb.append("5a");
        }
        //渐亮时长
        sb.append(numToHex8(jiangliang));
        //高亮时长
        sb.append(numToHex8(gaoliangchang));
        //渐暗时长
        sb.append(numToHex8(jianan));
        //高亮亮度
        sb.append(numToHex8(gaoliang));
        //节能亮度
        sb.append(numToHex8(jieneng));

        return sb.toString();
    }


}
